<template>
	<view class="main">
		<u-navbar :is-back="false" title="任务大厅" :background="background" :border-bottom="false">
			<view class="header">
				<view class="address">
					<u-icon name="map"></u-icon>{{poiName}}
				</view>
			</view>
		</u-navbar>
		<view class="tab">
			<view :class="type=='new'?'active':''" @click='handtype("new")'>新任务<text></text></view>
			<view :class="type=='stay_take'?'active':''" @click='handtype("stay_take")'>代取送<text></text></view>
			<view :class="type=='in_send'?'active':''" @click='handtype("in_send")'>配送中<text></text></view>
			<view :class="type=='end'?'active':''" @click='handtype("end")'>配送完成<text></text></view>
		</view>
		<view class="list" v-for="(item,index) in list" :key="index" @click="handdetail(item.id)">
			<view class="time">
				<text>下单时间:</text>{{item.create_time}}
				<image src="../../../static/images/dj.png" v-if="item.type==5" mode="aspectFit"></image>
				<image src="../../../static/images/drd.png" v-else-if="item.type==2" mode="aspectFit"></image>
				<image src="../../../static/images/jss.png" v-else-if="item.type==1" mode="aspectFit"></image>
				<image src="../../../static/images/dg.png" v-else mode="aspectFit"></image>
			</view>
			<view class="address">
				<view class="steps">
					<view>取</view><text></text>
					<view>送</view>
				</view>
				<view class="name">
					<view class="view"><view>{{item.start_infor.start_address}}</view><text>{{item.start_infor.start_address_detail}}</text></view>
					<view class="view"><view>{{item.end_infor.end_address}}</view><text>{{item.end_infor.end_address_detail}}</text></view>
				</view>
				<view class="distance">
					<view>{{item.start_infor.start_len}}km</view>
					<view>{{item.end_infor.end_len}}km</view>
				</view>
			</view>
			<view class="money">
				<view><text>天气补助：</text>¥{{item.commission.subsidy_t_price}}</view>
				<view><text>小费：</text>¥{{item.commission.tip}}</view>
				<view><text>总金额：</text>¥{{item.commission.gain_commission}}</view>
			</view>
			<view class="remarks">
				备注：<text>{{item.remark}}</text>
			</view>
			<view class="remarks">
				客户期望到达时间：<view>{{item.expect_time}}</view>
			</view>
			<view class="btn" @click="handorder(item.id)" v-if="type=='new'">
				立即接单
			</view>
			<view class="btns" v-if="type=='stay_take'">
				<view  @click.stop="handphone(item.start_infor.start_mobile)">联系商家</view>
				<view class="btn1" @click.stop="handshop(item.id)">确认到店</view>
			</view>
			<view class="btns" v-if="type=='in_send'">
				<view  @click.stop="handphone(item.end_infor.end_mobile)">致电买家</view>
				<view class="btn1" @click.stop="handservice(item.id)">确认送达</view>
			</view>
			<view class="btn" style="background-color:#999999;" v-if="type=='end'">
				已完成
			</view>
		</view>
		<view class="zwsj" v-if="list.length<=0&&!show">
			----暂无数据----
		</view>
		<u-loading :show="show" style="margin-top: 100rpx;"></u-loading>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				show:true,
				background: {
					backgroundColor: '#fff',
				},
				poiName:'',
				type: 'new',
				list:[]
			}
		},
		onShow() {
			let that=this
			uni.getLocation({
			    type: 'gcj02',
				geocode:true,
			    success: function (res) {
					global.$http.request({
						url: '/api/rider_location/index',
						data: {
							token: uni.getStorageSync('token'),
							lng:res.longitude,
							lat:res.latitude,
						}
					}).then(res => {
						that.handData()
					})
					that.poiName=res.address.poiName
			    }
			});
		},
		methods: {
			handdetail(id){
				if(this.type!='new'){
					uni.navigateTo({
						url:'../detail/detail?id='+id+'&type='+this.type
					})
				}
			},
			// 立即接单
			handorder(id){
				global.$http.request({
					url: '/api/rider_order/receive_order',
					data: {
						token: uni.getStorageSync('token'),
						order_id:id
					}
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							mask: true,
							duration: 1000
						})
						this.handData()
					}
				})
			},
			// 确认到店
			handshop(id){
				global.$http.request({
					url: '/api/rider_order/q_take',
					data: {
						token: uni.getStorageSync('token'),
						order_id: id,
					}
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							mask: true,
							duration: 1000
						})
					this.handData()
					}
				})
			},
			// 确认送达
			handservice(id){
				global.$http.request({
					url: '/api/rider_order/q_delivery',
					data: {
						token: uni.getStorageSync('token'),
						order_id: id,
					}
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							mask: true,
							duration: 1000
						})
					this.handData()
					}
				})},
			handtype(type){
				this.type=type
				this.list=[]
				this.handData()
			},
			handData() {
				this.show=true
				global.$http.request({
					url: '/api/rider_order/order',
					data: {
						token: uni.getStorageSync('token'),
						type: this.type
					}
				}).then(res => {
					this.list = res.data.data.list
					this.show=false
				})
			},
			handphone(phone){
				uni.makePhoneCall({
				    phoneNumber: phone
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;

		.main {
			width: 750rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.header {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 0 20rpx;

				.address {
					font-size: 24rpx;
					color: #000;
					width: 200rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}

			.tab {
				width: 750rpx;
				height: 70rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #fff;
				box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(116, 116, 116, 0.3);

				view {
					font-size: 30rpx;
					color: #000;
					width: 25%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					padding-top: 15rpx;

					text {
						display: block;
						width: 90rpx;
						height: 5rpx;
						margin-top: 15rpx;
					}
				}

				.active {
					color: #1DBE61;

					text {
						background-color: #1DBE61;
					}
				}
			}

			.list {
				width: 750rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(116, 116, 116, 0.3);
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 0 20rpx;

				.time {
					width: 710rpx;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.address {
					width: 710rpx;
					height: 240rpx;
					background: #FFFFFF;
					border: 1rpx solid #E6E6E6;
					border-radius: 20rpx;
					display: flex;
					align-items: flex-start;
					flex-direction: row;
					justify-content: space-between;
					padding: 30rpx 20rpx;

					.steps {
						height: 150rpx;
						width: 50rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: space-between;

						view {
							width: 40rpx;
							height: 40rpx;
							background: #3BDCAA;
							border-radius: 50%;
							background-color: #3BDCAA;
							font-size: 20rpx;
							color: #F0F3F8;
							display: flex;
							align-items: center;
							justify-content: center;
						}

						view:last-child {
							background: #F3444B;
						}

						text {
							display: block;
							width: 1rpx;
							height: 60rpx;
							border: 1rpx dashed #F0F3F8;
						}
					}

					.name {
						width: 450rpx;
						height: 195rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.view {
							display: flex;
							width: 450rpx;
							flex-direction: column;
							height: 80rpx;
							view{
								width: 450rpx;
								font-size: 28rpx;
								color: #000;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}

							text {
								width: 450rpx;
								font-size: 26rpx;
								color: #808080;
								margin-top: 10rpx;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}
						}
					}

					.distance {
						height: 150rpx;
						width: 120rpx;
						display: flex;
						flex-direction: column;
						align-items: flex-end;
						justify-content: space-between;
						font-size: 28rpx;
						color: #000;
					}

				}

				.money {
					width: 710rpx;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					view {
						font-size: 28rpx;
						color: #33AAFC;

						text {
							color: #000000;
						}
					}

					view:last-child {
						color: #E40E04;
					}
				}

				.remarks {
					width: 710rpx;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					font-size: 28rpx;
					color: #808080;

					text {
						color: #000000;
					}

					view {
						color: #33AAFC;
					}
				}

				.btn {
					width: 280rpx;
					height: 68rpx;
					background: #1DBE61;
					border-radius: 10rpx;
					margin: 20rpx 0;
					font-size: 28rpx;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.btns{
					width: 710rpx;
					padding:20rpx 0;
					display: flex;
					align-items: center;justify-content: center;
					view{
						width: 220rpx;
						height: 68rpx;
						border: 1rpx solid #1DBE61;
						border-radius: 10rpx;
						margin: 0 10rpx;
						display: flex;align-items: center;justify-content: center;
						color: #1DBE61;
						font-size: 28rpx;
					}
					.btn1{
						color: #fff;
						background-color: #1DBE61;
					}
				}
			}
		}
	}
</style>
